﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace Kursovaya_Pav.St.Dm
{
    public class Con_DB
    {
        public OleDbConnection sql_connect;
        public string Data_source;
        public Con_DB(string ids )
        {
            
            Data_source = ids;
            //строка соединения с БД
            string connect_string = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Data_source;

            //Создание обьекта для соединения
            sql_connect = new OleDbConnection(connect_string);
           


            //Открытие соединения с БД
            sql_connect.Open();
        }


        public void GetData(string sql, DataSet ds)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            OleDbCommand cmd = sql_connect.CreateCommand();
            cmd.CommandText = sql;     
            da.SelectCommand = cmd;
            da.Fill(ds);
           
     
        }

        public void SetData(string sql, byte[] val = null)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            OleDbCommand cmd = sql_connect.CreateCommand();
            cmd.CommandText = sql;
            if (val != null)
            {
                cmd.Parameters.AddWithValue("@DATA", SqlDbType.BigInt);
                cmd.Parameters[0].Value = val;
                cmd.Parameters[0].Size = val.Length;
            }
            cmd.ExecuteNonQuery();
            RefData();

        }
        public void RefData()
        {
            sql_connect.Close();
            sql_connect.Open();
        }
    }
}
